package com.gorkr.labuladong.data_struct.linked_list;

/**
 * @author gorkr
 * @date 2022/06/03 10:17
 **/
public class E83RemoveDuplicatesFromSortedList {
    class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public ListNode deleteDuplicates(ListNode head) {
        ListNode low = head, fast = head;
        while(fast!=null){
            if(low.val!= fast.val){
                low=low.next;
                low.val = fast.val;
            }
            fast=fast.next;
        }
        if(low==null){
            return null;
        }
        low.next = null;
        return head;
    }


}
    